import pandas as pd

# 读取数据
liepin = pd.read_csv("liepin/liepin/liepin.csv",
                     sep="\t",
                     header=None,
                     names=["job_name",
                            "location",
                            "job_salary",
                            "years",
                            "education",
                            "tag",
                            "company_name",
                            "hangye",
                            "rongzi",
                            "guimo",
                            "recruiter_name",
                            "recruiter_title"],
                     encoding="utf-8")

print(liepin.head())
import re

liepin["min_job_salary"] = liepin["job_salary"].apply(
    lambda x: re.findall(r"(\d+)-", x)[0] if len(re.findall(r"(\d+)-", x)) != 0 else "面议")

liepin["max_job_salary"] = liepin["job_salary"].apply(
    lambda x: re.findall(r"(\d+)k", x)[0] if len(re.findall(r"(\d+)k", x)) != 0 else "面议")

from pyecharts.faker import Faker

print([list(z) for z in zip(Faker.choose(), Faker.values())])

# value_counts ： 统计values的数量
# to_dict将序列转换成一个字典
# items将字典转换成一个列表
print([[k, v] for k, v in liepin["years"].value_counts().to_dict().items()])

tag_count = liepin["tag"].str.split(",", expand=True).stack().reset_index(level=1, drop=True).value_counts()

tag_coun1t = [(k, v) for k, v in tag_count.to_dict().items()]

print([list(z) for z in zip(Faker.guangdong_city, Faker.values())])

liepin["city"] = liepin["location"].apply(lambda x: x.split("-")[0])

city_counts = [[k, v] for k, v in liepin["city"].value_counts().to_dict().items()]
print(city_counts)

# 读取城市维表
citys = pd.read_csv("citys.txt", sep=",", header=None, names=["city", "province"], encoding="utf-8")

merge_data = pd.merge(liepin, citys, on="city")


example_data = [
    ("黑龙江", (127.9688, 45.368)),
    ("内蒙古自治区", (110.3467, 41.4899)),
    ("吉林", (125.8154, 44.2584)),
    ("辽宁", (123.1238, 42.1216)),
    ("河北", (114.4995, 38.1006)),
    ("北京", (114.4995, 38.1006)),
    ("天津", (117.4219, 39.4189)),
    ("山西", (112.3352, 37.9413)),
    ("陕西", (109.1162, 34.2004)),
    ("甘肃", (103.5901, 36.3043)),
    ("宁夏", (106.3586, 38.1775)),
    ("青海", (101.4038, 36.8207)),
    ("新疆维吾尔自治区", (87.9236, 43.5883)),
    ("西藏", (91.11, 29.97)),
    ("四川", (103.9526, 30.7617)),
    ("重庆", (108.384366, 30.439702)),
    ("山东", (117.1582, 36.8701)),
    ("河南", (113.4668, 34.6234)),
    ("江苏", (118.8062, 31.9208)),
    ("安徽", (117.29, 32.0581)),
    ("湖北", (114.3896, 30.6628)),
    ("浙江", (119.5313, 29.8773)),
    ("福建", (119.4543, 25.9222)),
    ("江西", (116.0046, 28.6633)),
    ("湖南", (113.0823, 28.2568)),
    ("贵州", (106.6992, 26.7682)),
    ("云南", (106.6992, 26.7682)),
    ("广西壮族自治区", (108.479, 23.1152)),
    ("广东", (108.479, 23.1152)),
    ("海南", (110.3893, 19.8516)),
    ("上海", (121.4648, 31.2891))
]
province_loc = dict(example_data)

province_counts = [(k, [province_loc[k][0], province_loc[k][1], v]) for k, v in
                   merge_data["province"].value_counts().to_dict().items()]

print(province_counts)
education_count = liepin["education"].value_counts().to_dict()
keys = [k for k in education_count.keys()]
values = [k for k in education_count.values()]